app.controller('AreaModalCtrl', function ($scope, $modalInstance, $modal, toaster, param, ajax) {

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	//获取组织列表
    (function() {
        ajax.call(new Req.GET({
            resource: 'organization/2/list'
        })).then(function(result) {
            $scope.orglist = result.result;
            //设置默认值
            if ($scope.param.data.organizationId != null) {
                var id = $scope.param.data.organizationId;
                var sel = 0;
                for (var i = 0; i < $scope.orglist.length; i++) {
                    sel++;
                    if ($scope.orglist[i].id == id) {
                        break;
                    }
                }

                $scope.orglist.selected = $scope.orglist[sel - 1];
            } else {
                $scope.orglist.selected = $scope.orglist[0];
            }
        }, function() { });
    })();

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			$scope.param.data.organizationId = $scope.orglist.selected.id;
			$modalInstance.close($scope.param);
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});